package com.ehotting.mqbd.zw.api.domain.netty;


import com.ehotting.mqbd.zw.api.constants.ActionConstants;
import com.ehotting.mqbd.zw.api.domain.protoc.ZwNodeResStreamOuterClass;
import com.google.protobuf.InvalidProtocolBufferException;


public class ClusterInfoQueryReq extends ZwCommPacket {

    private ZwNodeResStreamOuterClass.ZwNodeResList zwNodeResList;

    public ClusterInfoQueryReq() {
        super(ActionConstants.Cmd_ClusterInfoQueryStr);
    }

    public ZwNodeResStreamOuterClass.ZwNodeResList getZwNodeResList() {
        return zwNodeResList;
    }

    public void setZwNodeResList(ZwNodeResStreamOuterClass.ZwNodeResList zwNodeResList) {
        this.zwNodeResList = zwNodeResList;
    }

    @Override
    public void convertToHexStr() {
        if (zwNodeResList!=null) {
            this.setBuff(zwNodeResList.toByteArray());
        }
    }

    @Override
    public void convertToProp() {
        byte[] buff = this.getBuff();
        int bufSize = this.getHead().getBufSize();
        if (buff==null||bufSize==0){
            return;
        }
        try {
            this.zwNodeResList = ZwNodeResStreamOuterClass.ZwNodeResList.parseFrom(buff);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ClusterInfoQueryReq req = new ClusterInfoQueryReq();
        System.out.println(req.toString());
        ZwNodeResStreamOuterClass.ZwNodeResStream build = ZwNodeResStreamOuterClass.ZwNodeResStream.newBuilder()
                .setCpuMask(10000L).setIpAddr(11111).build();
        ZwNodeResStreamOuterClass.ZwNodeResList resList = ZwNodeResStreamOuterClass.ZwNodeResList.newBuilder().addNodeRes(build).build();
        req.setZwNodeResList(resList);
        req.convertToHexStr();
        System.out.println(req.toString());
    }
}
